<template>
	<div class="attribute-container">
		<div class="head">
			<div>
				<svg aria-hidden="true" class="svg-icon arrow" @click="handleExpand">
					<use v-if="!isExpand" href="#icon-right_arrow_normal"></use>
					<use v-else href="#icon-below_arrow_normal"></use> 
				</svg>
				<span>可视</span>
			</div>
			<span>
				<el-popover placement="bottom" trigger="click">
				  <template #reference>
					<svg aria-hidden="true" class="svg-icon dot-icon" >
						<use href="#icon-dot_normal"></use>
					</svg>
				  </template>
				  <div>
					<div>
						设置步长
					</div>
					<div>
						<el-input-number
							v-model="step"
							class="item"
							size="small"
							controls-position="right"
						/>
					</div>
				  </div>

				</el-popover>
			</span>
		</div>
 		<div class="body" v-if="isExpand" style="padding: 0 16px;">
			<div class="label">
				<span>范围</span>
			</div>
			<div class="items">
				<el-switch 
					v-model="enabled"
					inline-prompt
					active-text="启用"
					inactive-text="禁用"
					class="item"
					@change="onchange"
				/>
				
				<el-input-number
				    v-model="x"
					class="item"
					size="small"
					:step="step"
				    controls-position="right"
				    @change="onchange"
				/>
				<el-input-number
				      v-model="y"
					  size="small"
					  class="item"
					  :step="step"
				      controls-position="right"
				      @change="onchange"
				    />
			</div>
		</div>	 
	</div>
</template>

<script lang="ts" setup>
	const isExpand=ref(false);
	const props = defineProps({
	  value: {
		type: String,
		default: () => ""
	  },
	})
	const enabled=ref<Boolean>(true);
	const x=ref<number>(0);
	const y=ref<number>(5000);
	const step=ref(0.01);
	
	watch(props,() => {
			if(props.value){
				let _data=JSON.parse(props.value);
				enabled.value=_data.enabled;
				parseRange(_data.limit);
			}else{
				enabled.value=false;
				x.value=0;
				y.value=5000;
			}
		},
	    { immediate: true, deep: true },
	)


	function parseRange(v3:any) {
		if(v3){
			let v3r=v3.split(',');
			if(v3r && v3r.length>0){
				x.value=parseFloat(parseFloat(v3r[0]).toFixed(8));
			}
			if(v3r && v3r.length>1){
				y.value=parseFloat(parseFloat(v3r[1]).toFixed(8));
			}
		}else{
			x.value=0;y.value=0;
		}
	}
	
	const handleExpand=()=>{
		isExpand.value=!isExpand.value
	}
	
	const emits = defineEmits(['onchange'])
	const onchange=()=>{
		emits('onchange',{
			type:'visualRange',
			data:{
				enabled:enabled.value,
				limit:x.value+','+y.value
			}
		})
	}
	
	defineExpose({
	});
</script>

<style scoped>
	:deep(.el-input-number__decrease) {
	    background: #333333;
	    font-size: 13px;
		border-bottom: 1px solid #191919 !important;
		border-left: 1px solid #191919 !important;
		width: 16px;
	}
	:deep(.el-input-number__increase) {
	    background: #333333;
	    font-size: 13px;
		border-bottom: 1px solid #191919 !important;
		border-left: 1px solid #191919 !important;
		width: 16px;
	}
</style>